package koby99;

public class J19_CallBy {
	
	// call by value vs call by feference
	// 값 이동시키기swap
	// a = 3, b = 5 --> swap(3,5) --> a=5, b=3
	
	public static void main(String[] args) {
		int a = 3, b = 5; //기본 자료형
		int[] aa= {3};	  //참조 자료형
		int[] bb= {5};
		
		System.out.println("swap 호출전"+ a +","+ b);
		System.out.println("swap 호출전"+ aa[0] +","+ bb[0]);
		swap(a, b);   //기본 자료형
		swap(aa, bb); //참조 자료형
		System.out.println(a + ", "+ aa +", "+ aa[0]);
		/// aa는 주소를 부르지만
		/// aa[0]은 값을 불러온다는 것을 명심
		
		System.out.println("swap 호출후"+ a +","+ b);
		System.out.println("swap 호출후"+ aa[0] +","+ bb[0]);
		
		
	}// main
	static void swap(int x, int y){
		int tmp = x;
		x = y;
		y = tmp;
		System.out.println("swap 실행중"+ x +","+ y);
	}
	
	static void swap(int[] x, int[] y){
		System.out.println(x[0] +","+ y[0]);
		int tmp = x[0];
		x[0] = y[0];
		y[0] = tmp;
		System.out.println("swap 실행중"+ x[0] +","+ y[0]);
	}
}//class 
